<template>
  <div>
    <el-dialog v-model="visible" :title="title" width="50%">
      <div style="padding-right: 30px;">
        <el-form :model="form">
          <el-form-item label="初始账号" :label-width="formLabelWidth">
            <el-input v-model="form.initialAccount" />
          </el-form-item>
          <el-form-item label="初始密码" :label-width="formLabelWidth">
            <el-input v-model="form.initialPassword" />
          </el-form-item>
          <el-form-item label="会员到期时间" :label-width="formLabelWidth">
            <!--          <el-input v-model="form.expireTime" />-->
            <el-date-picker
                v-model="form.expireTime"
                type="date"
                placeholder="请选择会员到期时间"
                style="width:100%"
            />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="submitForm">确认</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, ref} from 'vue'
import {ElMessage, ElMessageBox} from "element-plus";
import BsApply from '../api/guild/bsApply'

const visible = ref(false)
const title=ref('')
const formLabelWidth = '140px'


// 表单默认值
let defaultForm = {
  id: '',
  initialAccount: '',
  initialPassword: '123456',
  expireTime: '',
}

let form = ref(defaultForm)


//编辑
function open(row){
  form.value = {...defaultForm}
  visible.value = true
  title.value='分配账号'
  // form.value = row
  form.value.id = row.id
  form.value.initialAccount = row.unitName
}

//定义触发器
let emit = defineEmits(['refresh'])

async function submitForm(){
  try {
    await ElMessageBox.confirm(
        '确定提交吗?',
        '重要提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
    )
    try {
      let formData = JSON.parse(JSON.stringify(form.value))

      let result = await BsApply.allocate(formData)
      ElMessage.success(result.data.data)
      visible.value = false
      //通知父组件更新数据
      emit('refresh')
    } catch (e) {
      console.log("e",e)
      ElMessage.error(e)
    }
  } catch (e) {

  }
}





//暴露出去
defineExpose({
  open,
})

</script>

<style  scoped>
</style>
